package com.gensdai.leliang.common.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.LayoutHelper;
import com.alibaba.android.vlayout.VirtualLayoutManager;
import com.gensdai.leliang.R;
import com.gensdai.leliang.common.bean.TitleBean;

import butterknife.BindView;
import butterknife.ButterKnife;

/**首页通用标题的适配  比如 ： 热卖推荐 more
 * Created by LT on 2017/6/15.
 */

public class BrandTitleAdapterRec extends DelegateAdapter.Adapter<BrandTitleAdapterRec.ContentTitleViewHolder> {

    private Context mContext;

    private LayoutHelper mLayoutHelper;


    private VirtualLayoutManager.LayoutParams mLayoutParams;
    int count = 1;

    String bean;

    public BrandTitleAdapterRec(Context context, LayoutHelper layoutHelper, String bean) {
        this(context, layoutHelper, bean, new VirtualLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    }

    public BrandTitleAdapterRec(Context context, LayoutHelper layoutHelper, String bean, @NonNull VirtualLayoutManager.LayoutParams layoutParams) {
        this.mContext = context;
        this.mLayoutHelper = layoutHelper;
        this.bean = bean;
        this.mLayoutParams = layoutParams;
    }

    @Override
    public LayoutHelper onCreateLayoutHelper() {
        return mLayoutHelper;
    }

    @Override
    public ContentTitleViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ContentTitleViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_brand_title, parent, false));
    }

    @Override
    public void onBindViewHolder(ContentTitleViewHolder holder, int position) {
        holder.itemView.setLayoutParams(
                new VirtualLayoutManager.LayoutParams(mLayoutParams));
        if (!TextUtils.isEmpty(bean)){
            holder.titleLable.setText(bean);
        }

    }

    @Override
    public int getItemCount() {
        return count;
    }


    static class ContentTitleViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.brandParentTitle)
        TextView titleLable;

        public ContentTitleViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        @Override
        protected void finalize() throws Throwable {
            super.finalize();
        }
    }

}
